package com.ethan.orika;

import com.ethan.model.Address;
import com.ethan.model.Person;
import com.ethan.model.PersonDto;
import lombok.*;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import ma.glasnost.orika.metadata.Type;
import ma.glasnost.orika.metadata.TypeBuilder;

/**
 * @author ethan
 * create 2018-04-11 下午2:20
 * desc 泛型映射
 **/
public class OrikaTest4 {
    public static void main(String[] args){

        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        Response<Person> response = new Response<>();
        Person person = new Person(1,"zs",new Address("北京市"));
        response.setData(person);
        Type<Response<Person>> fromType = new TypeBuilder<Response<Person>>() {}.build();
        Type<Response<PersonDto>> toType = new TypeBuilder<Response<PersonDto>>() {}.build();
        mapperFactory.classMap(Person.class,PersonDto.class)
                .field("id","personId")
                .field("name","personName")
                .byDefault().register();
        Response<PersonDto> responseDto = mapperFactory.getMapperFacade().map(response, fromType, toType);


        /**
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
        Response<String> response = new Response<>();
        response.setData("test");

        Type<Response<String>> fromType = new TypeBuilder<Response<String>>() {}.build();
        Type<Response<String>> toType = new TypeBuilder<Response<String>>() {}.build();
        Response<String> responseDto = mapperFactory.getMapperFacade().map(response, fromType, toType);
        **/


        String a="";
    }


    @Setter
    @Getter
    public static class Response<T>{
        private T data;
    }

}
